<template>
  <div>
    <ol class="zp-sidebar">
      <div class="menu">
        <template>
          <el-popover placement="left-start" title="" trigger="hover" content="">
            <div class="tc_content">
              <el-card class="box-card">
                <div slot="header" class="clearfix">
                  <h3>求职者</h3>
                </div>

                <div v-if="isLogin">
                  <!-- <div class="text item">
                  求职者：
                </div> -->
                  <div class="text item">
                    您好{{ps_userName}}，欢迎登录
                  </div>
                  <div class="text item">
                    <p><a :href="url+'/person/#/index'" target="_blank">个人中心</a></p>
                  </div>
                  <div class="text item">
                    <p @click.stop="logOutPersonal">退出登录</p>
                  </div>
                </div>

                <div v-else>
                  <!-- <div class="text item">
                  求职者：
                </div> -->
                  <div class="text item">
                    您还没有未登录
                  </div>
                  <!-- <div class="text item">
                    <p>
                      <a :href="url+'/person/#/register'" target="_blank">注册去找工作</a>
                    </p>
                  </div> -->
                  <div class="text item">
                    <p>
                      <a :href="url+'/person/#/login'" target="_blank">已有账号去登录</a>
                    </p>
                  </div>
                </div>

              </el-card>
            </div>
            <li class="zp-sidebar__li zp-qq-img" slot="reference">
            </li>
          </el-popover>
        </template>
        <template>
          <el-popover placement="left-start" title="" trigger="hover" content="">
            <div class="tc_content">
              <el-card class="box-card">
                <div slot="header" class="clearfix">
                  <h3> 企业</h3>
                </div>
                <div v-if="isEpLogin">
                  <!-- <div class="text item">
                  企业：
                </div> -->
                  <div class="text item">
                    您好 &nbsp; {{ ep_userName}}，欢迎登录
                  </div>
                  <div class="text item">
                    <p><a :href="url+'/company/#/home'" target="_blank">企业中心</a></p>
                  </div>
                  <div class="text item">
                    <p @click.stop="logOutCompany">退出登录</p>
                  </div>
                </div>
                <div v-else>
                  <!-- <div class="text item">
                  企业：
                </div> -->
                  <div class="text item">
                    您还没有未登录
                  </div>
                  <div class="text item">
                    <p><a :href="url+'/company/#/register'" target="_blank">注册免费发职位</a></p>
                  </div>
                  <div class="text item">
                    <p><a :href="url+'/company/#/login'" target="_blank">已有账号去登录</a></p>
                  </div>
                </div>
              </el-card>
            </div>
            <li class="zp-sidebar__li zp-enterprise-img zp-sidebar__line" slot="reference"></li>
          </el-popover>
        </template>
        <!-- <el-popover placement="left-start" title="" trigger="hover" content="">
          <div class="tc_content">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <h3>更多业务请电话咨询</h3>
              </div>
              <div class="text item">
                招聘热线：0731-28811243
              </div>
              <div class="text item">
                档案职称：0731-28818405
              </div>
              <div class="text item">
                流动党员：0731-28681683
              </div>
              <div class="text item">
                求职推荐： 0731-28681682
              </div>
              <div class="text item">
                其他业务： 0731-28681053
              </div>
            </el-card>
          </div>
          <li class="zp-sidebar__li zp-phone-img zp-sidebar__line" slot="reference"></li>
        </el-popover> -->
      </div>
      <div class="backUp" @click="toTop">
        <li class="zp-sidebar__li">
          <!-- <img src="../../../assets/img/backTop.png" alt=""> -->
        </li>
      </div>
    </ol>
  </div>
</template>
<script>
import bus from '@/components/common/bus';
import { logOut } from '../../../api/login';
export default {
  name: 'rightPopver',
  props: ['isLogin', 'isEpLogin'],
  data () {
    return {
      url: process.env.VUE_APP_URL,
      ps_userName: '',
      ep_userName: ''
    }
  },
  methods: {
    // 监听高度
    handleScroll () {
      let scrolltop = document.documentElement.scrollTop || document.body.scrollTop;
      scrolltop > 30 ? (this.gotop = true) : (this.gotop = false);
    },
    // 返回顶部
    toTop () {
      let top = document.documentElement.scrollTop || document.body.scrollTop;
      // 实现滚动效果 
      const timeTop = setInterval(() => {
        document.body.scrollTop = document.documentElement.scrollTop = top -= 50;
        if (top <= 0) {
          clearInterval(timeTop);
        }
      }, 8);
    },
    // 个人 退出登录
    logOutPersonal () {
      logOut().then(data => {
        console.log(data);
        if (data.success) {
          localStorage.setItem('ps_Authorization', '');
          localStorage.setItem('ps_userName', '');
          localStorage.setItem('ps_userId', '');
          // changeIsLogin 个人登陆状态
          bus.$emit('changeIsLogin', false);
        } else {
          this.$message.error(`${data.msg}`);
        }
      });
    },
    // 企业 退出登录
    logOutCompany () {
      logOut().then(data => {
        console.log(data);
        if (data.success) {
          localStorage.setItem('ep_Authorization', '');
          localStorage.setItem('ep_userName', '');
          // changeEpLogin 企业登陆状态
          bus.$emit('changeEpLogin', false);
        } else {
          this.$message.error(`${data.msg}`);
        }
      });
    }
  },
  mounted () {
    // 此处true需要加上，不加滚动事件可能绑定不成功
    window.addEventListener("scroll", this.handleScroll, true);
  },
  created () {
    this.ps_userName = localStorage.getItem('ps_userName') || '';
    this.ep_userName = localStorage.getItem('ep_userName') || '';
    bus.$on('changeUserName', msg => {
      this.ps_userName = msg;
    });
  }
}
</script>
<style >
.zp-sidebar {
    width: 48px;
    border-radius: 24px;
    padding: 10px 0 5px;
    position: fixed;
    right: 0;
    z-index: 1;
    top: 155px;
}
.zp-sidebar .menu {
    width: 48px;
    height: 122px;
    margin-bottom: 35px;
    border-radius: 20px;
    background-color: #fff;
}

.zp-sidebar .backUp {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: #fff;
    left: 16%;
    background: url('../../../assets/img/backTop.png') no-repeat;
}

.zp-sidebar .backUp:hover {
    color: #fff;
    background: none;
    border-radius: 50%;
    left: 16%;
    background: url('../../../assets/img/backTopC.png');
}

.zp-phone-img {
    left: 16%;
    background: url('../../../assets/img/phone.png') no-repeat;
}
.zp-phone-img:hover {
    left: 16%;
    background: url('../../../assets/img/phoneC.png') no-repeat;
}
.zp-qq-img {
    left: 16%;
    background: url('../../../assets/img/person.png') no-repeat;
}
.zp-qq-img:hover {
    left: 16%;
    background: url('../../../assets/img/personHover.png') no-repeat;
}

.zp-enterprise-img {
    left: 16%;
    background: url('../../../assets/img/enterprise.png') no-repeat;
}
.zp-enterprise-img:hover {
    left: 16%;
    background: url('../../../assets/img/enterpriseHover.png') no-repeat;
}

.zp-sidebar__li {
    align-items: center;
    display: flex;
    justify-content: center;
    height: 40px;
    text-align: center;
    cursor: pointer;
    margin-bottom: 35px;
    margin-top: 10px;
    position: relative;
}
.line {
    width: 80%;
    height: 2px;
    /* margin-top: 25px; */
    /* background: rgba(232, 232, 232, 1); */
}

li,
ul {
    list-style: none;
}
.zp-iconfont {
    font-family: 'zp-iconfont' !important;
    font-size: 16px;
    font-style: normal;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
.zp-sidebar__link {
    display: block;
    margin: 0 4px;
    width: 40px;
    height: 40px;
    line-height: 40px;
    border-radius: 20px;
    color: #bababa;
}
.zp-sidebar__line::after {
    content: '';
    width: 60%;
    height: 2px;
    position: absolute;
    top: -20px;
    left: 2px;
    background: rgba(232, 232, 232, 1);
}

.text {
    font-size: 14px;
}
.text p,
.text a {
    color: #0093ff;
    font-weight: 600;
    cursor: pointer;
}

.item {
    margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
    display: table;
    content: '';
}
.clearfix:after {
    clear: both;
}

.box-card {
    width: 100%;
}

.el-card.is-always-shadow,
.el-card.is-hover-shadow:focus,
.el-card.is-hover-shadow:hover {
    box-shadow: 0 0px 0px 0 rgba(0, 0, 0, 0);
}
.el-card {
    border: 0px solid #ebeef5;
}
</style>